<?php
declare (strict_types=1);

namespace app\backend\controller\v1;

use app\common\model\Comment as CommentModel;

class Comment extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {

        $model = new CommentModel();
        $datas = listComment($model->with(['member','article'])->order('id desc')->select());
        return sucessMsg(200, '获取成功！',$datas);
    }

    /**
     * 删除指定资源
     *
     * @param int $id
     * @return \think\Response
     */
    public function delete()
    {
        $id = input('id/d', 0);
        if (empty($id)) {
            return errMsg(422, 'id不能为空');
        }
        $data = CommentModel::where('id', $id)->find();
        if (empty($data))
            return errMsg(422, '无效id');
        if (CommentModel::destroy($id))
            return sucessMsg(200, '删除成功');
        return errMsg(422, '删除失败');
    }
}

